<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>configurationObjectPattern</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

<script>
$(document).ready(function () {
	
	var agg = (function () {
		
		var index = 0,
		    data = [1, 2, 3, 4, 5],
		    length = data.length;
		    
		return {
			
			next: function () {
				var element;
				if (!this.hasNext()) {
					return null;
				}
				element = data[index];
				index = index + 2;
				return element;
			},
			
			hasNext: function () {
				return index < length;
			},
			
			rewind: function () {
				index = 0;
			},
			
			current: function () {
				return data[index];
			}
			
		};
		    
	}());
	
	while (agg.hasNext()) {
		console.log(agg.next());
	}
	
	// 처음으로 되돌린다.
	agg.rewind();
	console.log(agg.current());
	
});



</script>

</head>
    <body>
	    <h3>Iterator 패턴</h3>
    </body>
</html>